<?php include '../../common/view/header.html.php';?>
<?php include '../../common/view/datepicker.html.php';?>
<style type="text/css">
    .bold {
        font-weight: bold;
    }
</style>
<div id='mainContent' class='main-row'>
  <div class='side-col col-lg'>
    <?php include 'blockreportlist.html.php';?>
  </div>
  <div class='main-col'>
    <div class='cell'>
      <div class="table-row" id='conditions'>
        <div class='col-sm-3'>
          <div class='input-group'>
            <span class='input-group-addon'><?php echo $lang->report->project;?></span>
            <?php echo html::select('project', $projects, $project, "class='form-control chosen' onchange='changeParams(this)'");?>
          </div>
        </div>
        <div class='col-sm-3'>
          <div class='input-group'>
            <span class='input-group-addon'><?php echo $lang->report->dept;?></span>
            <?php echo html::select('dept', $depts, $dept, "class='form-control chosen' onchange='changeParams(this)'");?>
          </div>
        </div>
        <div class='input-group w-400px input-group-sm'>
          <span class='input-group-addon'><?php echo $lang->projectCommon . $lang->report->taskOverData;?></span>
          <div class='datepicker-wrapper datepicker-date'><?php echo html::input('begin', $begin, "class='form-control form-date' onchange='changeParams(this)'");?></div>
          <span class='input-group-addon'><?php echo $lang->report->to;?></span>
          <div class='datepicker-wrapper datepicker-date'><?php echo html::input('end', $end, "class='form-control form-date' onchange='changeParams(this)'");?></div>
        </div>
      </div>
    </div>
    <?php if(empty($projects)):?>
    <div class="cell">
      <div class="table-empty-tip">
        <p><span class="text-muted"><?php echo $lang->error->noData;?></span></p>
      </div>
    </div>
    <?php else:?>
    <div class='cell'>
      <div class='panel'>
        <div class="panel-heading">
          <div class="panel-title"><?php echo $title;?></div>
          <?php
            $checkObject = new stdclass();
            $checkObject->project = 0;
          ?>
          <nav class="panel-actions btn-toolbar"><?php if(common::hasPriv('report', 'export', $checkObject)) echo html::submitButton($lang->report->export, '', 'btn btn-primary btn-block');?></nav>
        </div>
        <div data-ride='table'>
          <table class='table table-condensed table-striped table-bordered table-fixed no-margin table-hover' id='projectUserSummary'>
            <thead>
              <tr class='colhead'>
                <th class='w-200px'><?php echo $lang->report->code;?></th>
                <th><?php echo $lang->report->projectName;?></th>
                <th class='w-150px'><?php echo $lang->report->user;?></th>
                <th class="w-150px text-center"><?php echo $lang->report->myConsumed;?></th>
                <th class="w-150px text-center"><?php echo $lang->report->projectsTotal;?></th>
              </tr>
            </thead>
            <tbody>
            <?php
                $totalUserTime = 0;
                $totalProjectTime = 0;
            ?>
              <?php foreach($projectUserSummary as $id  =>$project):?>
                  <?php $i = 1; ?>
                  <?php foreach ($project['user'] as $finishedBy => $user ): ?>
                    <?php if ($i == 1): ?>
                      <tr class="text-center">
                          <td rowspan="<?php echo count($project['user']);?>" class="text-left"><div data-toggle="tooltip" data-placement="left" title="<?php echo $project['code'];?>"><?php echo $project['code'];?></div></td>
                          <td rowspan="<?php echo count($project['user']);?>" class="text-left"><div data-toggle="tooltip" data-placement="left" title="<?php echo $project['name'];?>"><?php echo html::a($this->createLink('project', 'view', "projectID=$id"), $project['name']);?></div></td>
                        <td class="text-left"><?php echo $user["finishedBy"];?></td>
                        <td><?php echo $user['consumed']; $totalUserTime += $user['consumed']; ?></td>
                        <td rowspan="<?php echo count($project['user']);?>"><?php echo $project['consumed']; $totalProjectTime += $project['consumed']; ?></td>
                      </tr>
                    <?php else:?>
                      <tr class="text-center">
                        <td class="text-left"><?php echo $user["finishedBy"];?></td>
                        <td><?php echo $user['consumed']; $totalUserTime += $user['consumed'];?></td>
                      </tr>
                    <?php endif; ?>
                    <?php $i++; ?>
                  <?php endforeach;?>
            <?php endforeach;?>
            <tr>
                <td class="text-center bold">合计</td>
                <td></td>
                <td></td>
                <td class="text-right bold"><?php echo $totalUserTime; ?></td>
                <td class="text-right bold"><?php echo $totalProjectTime; ?></td>
            </tr>
            </tbody>
          </table>
        </div>
      </div>
    </div>
    <?php endif;?>
  </div>
</div>
<?php include '../../common/view/footer.html.php';?>
